package easy;

public class Solution_1640 {
    public boolean canFormArray(int[] arr, int[][] pieces) {
        for (int i = 0; i < arr.length; ) {
            int[] temps = null;
            for (int[] piece : pieces) {
                if (piece[0] == arr[i]) {
                    temps = piece;
                    break;
                }
            }
            if (temps == null) {
                return false;
            }
            for (int temp : temps) {
                if (temp != arr[i++]) {
                    return false;
                }
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Solution_1640 model = new Solution_1640();
        System.out.println(model.canFormArray(new int[]{91, 4, 64, 78}, new int[][]{{78}, {4, 64}, {91}}));
    }
}
